<?php
/*
 * 首页
 * david.yan (david.yan@qq.com) by 2013
 * 北京泰和盈动科技有公司 版权所有
 */
class common extends actionAbstract {

    public $title = '';
    public $css = array();
    public $modules = array();
    public $menu = array();
    public $pos = 0;
	public $type=0;
	public $leftpos=0;
	
	/*
     * 构造
     */
    function __construct() {
        parent::__construct();

    }
	
    /*
     * 登录页面
     */
    public function login(){
		$this->leftpos=0;
        include $this->loadView();
    }
    /*
     * 验证登录信息
     */
    public function checkLogin(){
        if($_POST){
            $this->loadHelper('extend');
            if(!$_POST['username']){
                exit(json_encode(array('state' => 0, 'info' =>  '请输入用户名')));
            }
            if(!$_POST['password']){
                exit(json_encode(array('state' => 0, 'info' =>  '请输入密码')));
            }
            if(!$_POST['verify']){
                exit(json_encode(array('state' => 0, 'info' =>  '请输入验证码')));
            }
            // 判断验证码
            if(!($_POST['verify']==$_SESSION['verifycode_content'])){
                exit(json_encode(array('state' => 0, 'info' =>  '验证码错误')));
            } 
            // 判断用户名密码
            else{
               $this->loadModel('sys','account');
               $password=md5($_POST['password']);
               $sql="select * from sys_account where username='".$_POST['username']."' and password='".$password."' and status=1";
               $re=$this->sys->accountModel->fetchRow($sql);
               if(!$re){
                    exit(json_encode(array('state' => 0, 'info' =>  '用户名或密码错误')));
               }else{
                    //存储ip  最后时间
                    $data['lastip']=$_SERVER["REMOTE_ADDR"];
                    $data['lasttime']=time();
                    $this->sys->accountModel->update($data,$re['id']);
                    //存储cookie
                    acl::setCookie("admininfo",$re);
    				$url=$this->url('system/website');
    				exit(json_encode(array('state' => 1, 'info' =>  '登录成功','url'=>$url)));
               }
            }
        }
    }
    /**
    * @desc 安全退出
    */
    public function logout(){
        $this->loadHelper('extend');
        setcookie("admininfo", "", time() - 3600,'/');
        ajaxReturn ('','退出成功', 1 );exit;
    }

    /**
    * @desc 验证码
    */
    function yzmCode(){
        $this->loadHelper("verifyCode");
        $code = new verifyCode(50,26);
        echo $code;
    }
    
     function delc(){
         $this->loadHelper('js');
         $js=new js();
         acl::setCookie("admininfo","");
         header("location:/index.php/sysadmin/index");
    }
    /**
	*错误提示
	**/
	function alert(){
	$msg=$_GET['msg'];
	$sleep=$_GET['sleep'];
	$state=0;
	 include $this->loadView();
	}
}
?>